﻿
using T.FAS.Runtime.DataAccess.Engine.ValidateChecker.Entity;

namespace T.FAS.Runtime.DataAccess.Engine
{
    /// <summary>
    /// Long类型校验
    /// </summary>
    public class LongValidateFactory : CommonFactory
    {
        public override IColumnValidater GetDataTypeValidater()
        {
            return new LongDataTypeValidater();
        }

        public override IColumnValidater GetLengthValidater()
        {
            return new LongLengthValidater();
        }
    }
    public class LongDataTypeValidater : IColumnDataTypeValidater
    {
        public ValidateCheckItem Validate(ValidateCheckItem item)
        {
            if (item.Result.IsStop)
                return item;
            var inputVal = item.InputValue.ToString();
            //数据类型验证
            if (!long.TryParse(inputVal, out long value))
            {
                item.Result.Flag = false;
                item.Result.IsStop = true;
                item.Result.Msg.Append(string.Format(ValidateConst.DataTypeErrorTemp, item.CheckElement.Name, inputVal, item.CheckElement.DataType));
            }
            else
            {
                item.ConvertValue = value;
            }
            return item;
        }
    }

    public class LongLengthValidater : IColumnLengthValidater
    {
        public ValidateCheckItem Validate(ValidateCheckItem item)
        {
            return item;    //Long不做长度校验
        }
    } 
}
